package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OrderBean;
import com.project.bean.UserBean;
import com.project.mapper.ICartMapper;
import com.project.service.ICartService;
import com.project.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.security.Provider;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @RequestMapping("addOrder")
    public String addOrder(OrderBean order, HttpServletRequest req) {
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        order.setUserId(user.getId());
        orderService.add(order);
        return "ok";
    }

    @RequestMapping("cutByItem")
    public IPage<OrderBean> cutByItem(Integer pageNO, String status, LocalDate startDate, LocalDate endDate, HttpServletRequest req) {
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        return orderService.cutByItem(pageNO, user.getId(), status, startDate, endDate);
    }

    @RequestMapping("findByOrderId")
    public OrderBean findByOrderId(Integer orderId) {
        return orderService.findByOrderId(orderId);
    }

    @RequestMapping("send")
    public String send(Integer orderId) {
        orderService.send(orderId);
        return "ok";
    }

    @RequestMapping("findByStatus")
    public List<OrderBean> findByStatus() {
        return orderService.findByStatus();
    }

    @RequestMapping("compile")
    public String compile(Integer orderId){
        orderService.compile(orderId);
        return "ok";
    }
}
